import { DynamicModule, Module } from '@nestjs/common';
import { CloudinaryService } from './services/cloudinary.service';
import { CloudinaryOptions } from './interfaces/cloudinary-options.interface';
import { CloudinaryController } from './controllers/cloudinary.controller';

@Module({})
export class CloudinaryModule {
  /**
   * 注册 Cloudinary 模块
   * @param options Cloudinary 配置选项
   * @returns 动态模块
   */
  static register(options: CloudinaryOptions): DynamicModule {
    return {
      module: CloudinaryModule,
      controllers: [CloudinaryController],
      providers: [
        {
          provide: 'CLOUDINARY_OPTIONS',
          useValue: options,
        },
        {
          provide: CloudinaryService,
          useFactory: () => {
            const service = new CloudinaryService();
            service.initializeCloudinary(options);
            return service;
          },
        },
      ],
      exports: [CloudinaryService],
    };
  }
}
